package com.gz.steak.modules.system.mapper;

import com.gz.steak.modules.system.pojo.model.LoginModel;
import com.gz.steak.modules.system.pojo.model.SysUserModel;
import com.gz.steak.modules.system.pojo.dataobject.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface SysUserMapper {

    /**
     * 查询用户密码
     * @param username
     * @return
     */
    @Select("SELECT r.id , u.user_nick_name , ur.role_id , r.role_remark , r.role_name , u.user_password , u.user_name FROM sys_user u , sys_user_role ur , sys_role r where u.id = ur.user_id and ur.role_id = r.id and u.user_name = #{username}")
    List<LoginModel> getUserInfo(String username);

    /**
     * 用户注册
     * @param username
     * @param password
     */
    @Insert("insert into sys_user(username,password,role,ip,time,address) value(#{username},#{password},1,#{ip},#{date},#{address})")
    void register(String username, String password,String ip,String date,String address);

    /**
     * 获取用户列表
     * @return
     */
    @Select("SELECT u.id,user_name,user_nick_name,u.user_dept_id,user_email,user_sex,user_phone,user_status,user_birthday,u.create_by,u.create_time,d.dept_name " +
            "FROM sys_user u , sys_dept d where u.user_dept_id = d.id")
    List<SysUserModel> getUserList(@Param("nodeId") Long nodeId);
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table sys_user
     *
     * @mbg.generated Fri Mar 20 20:56:22 CST 2020
     */
    int deleteByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table sys_user
     *
     * @mbg.generated Fri Mar 20 20:56:22 CST 2020
     */
    int insert(SysUser record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table sys_user
     *
     * @mbg.generated Fri Mar 20 20:56:22 CST 2020
     */
    int insertSelective(SysUser record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table sys_user
     *
     * @mbg.generated Fri Mar 20 20:56:22 CST 2020
     */
    SysUser selectByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table sys_user
     *
     * @mbg.generated Fri Mar 20 20:56:22 CST 2020
     */
    int updateByPrimaryKeySelective(SysUser record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table sys_user
     *
     * @mbg.generated Fri Mar 20 20:56:22 CST 2020
     */
    int updateByPrimaryKey(SysUser record);

    @Select("select id from sys_user where user_name = #{userName}")
    Long queryIdByUserName(String userName);

    @Select("select user_name from sys_user where user_name = #{userName}")
    String findUserNameIsExists(String userName);

    @Select("SELECT u.id,user_name,user_email,user_dept_id,user_nick_name,user_sex,user_phone,user_status,user_birthday,u.create_by,u.create_time,d.dept_name FROM sys_user u , sys_dept d where u.user_dept_id = d.id and u.user_dept_id = #{nodeId}")
    List<SysUserModel> getUserListOfOne(@Param("nodeId") Long nodeId);

    @Select("SELECT u.id,user_name,user_email,user_dept_id,user_nick_name,user_sex,user_phone,user_status,user_birthday,u.create_by,u.create_time,d.dept_name FROM sys_user u , sys_dept d where u.user_dept_id = d.id and d.dept_parent_id = #{nodeId}")
    List<SysUserModel> getUserListOfMore(@Param("nodeId") Long nodeId);

    @Update("update sys_user set user_status = #{status} where id = #{id}")
    int frozenById(Long id , int status);
}